#include <iostream>
using namespace std;
template <typename T>
class Node {
public:
	template <typename T>
	friend class binaryTree;
	Node(T value);
	Node(T value,Node<T>* left,Node<T>* right);
	void setLeft(Node<T>* left);
	void setRight(Node<T>* right);
	~Node();
private:
	T value;
	Node<T>* leftChild;
	Node<T>* rightChild;
};
template <typename T>
Node<T>::Node(T value) {
	this->value = value;
	leftChild = nullptr;
	rightChild = nullptr;
}
template <typename T>
Node<T>::~Node() {

}
template <typename T>
Node<T>::Node(T value,Node<T>* left,Node<T>* right) {
	this->value = value;
	leftChild = left;
	rightChild = right;
}
template <typename T>
void Node<T>::setLeft(Node<T>* left) {
	leftChild = left;
}
template <typename T>
void Node<T>::setRight(Node<T>* right) {
	rightChild = right;
}

template <typename T>
class binaryTree {
public:
	binaryTree();
	~binaryTree();
	void inOrderTraverse(Node<T>* root);
	void inverseTraverse(Node<T>* root, ofstream& out,int depth);
	void setRoot(Node<T>* r);
	Node<T>* getRoot();
	void addChild(Node<T>* left, Node<T>* right);
private:
	Node<T>* root;
};
template <typename T>
binaryTree<T>::binaryTree() {
	root = new Node<T>(0);
}
template <typename T>
binaryTree<T>::~binaryTree() {
	delete root;
}
template <typename T>
void binaryTree<T>::addChild(Node<T>* left, Node<T>* right){
	root->leftChild = left;
	root->rightChild = right;
}
template <typename T>
void binaryTree<T>::setRoot(Node<T>* r) {
	root = r;
}
template <typename T>
Node<T>* binaryTree<T>::getRoot() {
	return root;
}
template <typename T>
void binaryTree<T>::inOrderTraverse(Node<T>* root) {
	if (root == nullptr)return;
	inOrderTraverse(root->leftChild);
	cout << root->value << " ";
	inOrderTraverse(root->rightChild);
}
template <typename T>
void binaryTree<T>::inverseTraverse(Node<T>* root,ofstream& out,int depth) {
	Node<T>* tool = new Node<T>(0,nullptr,nullptr);
	if (root == nullptr)return;
	depth++;
	inverseTraverse(root->rightChild,out,depth);
	for (int i = 1; i < depth; i++)
		out << tool->value <<tool->value << tool->value << tool->value << tool->value;
	out <<root->value << '\n';
	inverseTraverse(root->leftChild,out,depth);
}